package com.isunland.managesystem.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.CustomerDialog;

/**
 * Created by lenovo on 2016/12/7.
 */
public class EditKindDialogFragment extends DialogFragment {
  protected static final String EXTRA_KIND =
      "com.isunland.managesystem.ui.EditKindDialogFragment.EXTRA_KIND";
  private static final int[] titleIds = { R.string.words, R.string.data, R.string.file };
  private static final String[] titleStrs = new String[titleIds.length];
  private String kindCode;
  private String kindName;

  @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = new AlertDialog.Builder(getActivity()).setSingleChoiceItems(getTitleStrs(), 0,
        new DialogInterface.OnClickListener() {

          @Override public void onClick(DialogInterface dialog, int which) {
            switch (which) {
              case 0:
                kindCode = "01";
                break;
              case 1:
                kindCode = "02";
                break;
              case 2:
                kindCode = "03";
                break;
            }

            kindName = getTitleStrs()[which];
            Intent i = new Intent();
            i.putExtra(EXTRA_KIND, new CustomerDialog(kindName, kindCode));
            getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, i);
            dialog.dismiss();
          }
        }).create();
    return dialog;
  }

  private String[] getTitleStrs() {
    for (int i = 0; i < titleIds.length; i++) {
      titleStrs[i] = getActivity().getResources().getString(titleIds[i]);
    }
    return titleStrs;
  }
}